package edu.drawing1;

import java.awt.*;
import java.awt.event.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class DemoDrawing1 extends JFrame {
	private DrawingArea left = new DrawingArea();
	private DrawingArea right = new DrawingArea();

	public DemoDrawing1() {
		left.setBackground(Color.WHITE);
		right.setBackground(Color.BLACK);
		JButton changeColorButton = new JButton("Randomize Colors");
		changeColorButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				left.setMyColor(randomColor());
				right.setMyColor(randomColor());
			}

			
		});

		JPanel content = new JPanel();
		content.setLayout(new BorderLayout(5,5));
		content.add(changeColorButton, BorderLayout.NORTH);
		content.add(left, BorderLayout.WEST);
		content.add(right, BorderLayout.EAST);
		
		setContentPane(content);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("Demo Drawing");
		this.setLocationRelativeTo(null);
		this.pack();
		
		
		
	}
	private static Color randomColor() {
		// TODO Auto-generated method stub
		return new Color(
				(int) (Math.random() * 256), 
				(int) (Math.random() * 256), 
				(int) (Math.random() * 256));
	}
	public static void main(String args[]){
		JFrame window = new DemoDrawing1();
		window.setVisible(true);
	}
}
